# -*- coding: utf-8 -*-

__authur__ = 'Yu XH'


import numpy as np

from myAI.attdamage.ruling_data import *


def calc_damage_mean(tar_type, attack_level, armor_type=ArmorType.Composit, keep=0, blood=3, rect_value=0):
    """
    根据攻击等级attack_level，目标的装甲类型armor_type，目标的车数blood，随机数修正值rect_value
    计算期望的最终战损结果
    :param tar_type: {int} 目标类型（步兵、车辆、空中算子），参见BopType, const.py
    :param attack_level: {int} 攻击等级
    :param armor_type: {int} 装甲类型
    :param keep: {int} 是否压制的判断，只对步兵算子有效
    :param blood: {int} 车/班数
    :param rect_value: {int} 修正值
    :return:
    """
    if tar_type == BopType.Vehicle:
        combat_results = CombatResultsVehicleDirect().get_combat_results(attack_level, blood)
        damage_rects = DamageRectVehicleDirect().get_damage_rects(armor_type, rect_value)
    elif tar_type == BopType.Infantry:
        combat_results = CombatResultsInfantryDirect().get_combat_results(attack_level, keep)
        damage_rects = DamageRectInfantryDirect().get_damage_rects(rect_value)
    else:
        raise Exception('目标算子类型输入错误！')
    prob_matrix = Probability.matrix_2d
    n_rows, n_cols = prob_matrix.shape
    return np.sum(
        prob_matrix *
        np.maximum(
            np.tile(combat_results.reshape(-1, 1), (1, n_cols)) + np.tile(damage_rects.reshape(1, -1), (n_rows, 1)),
            np.zeros((n_rows, n_cols))
        )
    )


if __name__ == '__main__':
    a = calc_damage_mean(BopType.Vehicle, 1, ArmorType.Composit, rect_value=-2)
    print(a)
